# This code is hosted on http://code.google.com/p/lenthorp/
# Freely available for use in applications, but should NOT be modified
# Email all comments to lenthorpresearch@gmail.com


# General virtual parameter container class
class ModelParameters:
    
    def __init__(self):
        self.p = {}
        self.Bounds = {}

    def getSize(self):
        return len(self.p.items())


class PricingParameters:

    def __init__(self, parameterNames):
        self.p = []
        self.pNames = parameterNames

    def getSize(self):
        return len(self.p)

    def addPricingSet(self, parameterValues, price, weight = 1.0):
        newPriceSet = ModelParameters()
        for idx in range(len(self.pNames)):
            newPriceSet.p[self.pNames[idx]] = parameterValues[idx]
        newPriceSet.p['price'] = price
        newPriceSet.p['weight'] = weight
        self.p.append(newPriceSet)


class OptimiseParameters(ModelParameters):

##    def __init__(self):
##        ModelParameters.__init__(self)
        
        
    def getVector(self, names):
        returnVec = [0 for idx in range(len(names))]
        for idx in range(len(names)):
            returnVec[idx] = self.p[names[idx]]

    def setBound(self, name, bound, isMin=True):
        self.Bounds[name + '_' + ('min' if isMin else 'max')] = bound
        
        